var urbanIncomeType = [];
var urbanIncomeValue = [];
var urbanExpenditureType = [];
var urbanExpenditureValue = [];
var ruralIncomeType = [];
var ruralIncomeValue = [];
var ruralExpenditureType = [];
var ruralExpenditureValue = [];
var urbanIncomeList = [];
var ruralIncomeList = [];
var urbanExpenditureSum = 0;
var ruralExpenditureSum = 0;
var url = location.search; //获取url中"?"符后的字串
if (url.indexOf("?") != -1) {
    address = decodeURI(url.substr(1).split("=")[1].split("?")[0]);
    year = decodeURI(url.substr(1).split("=")[2]);
}

$.ajax({
    type: "post",
    async: false,            //异步请求（同步请求将会锁住浏览器，用户其他操作必须等待请求完成才可以执行）
    url: "ZhejiangIEServlet?address=" + address + "&year=" + year,    //请求发送到TestServlet处
    data: {},
    dataType: "json",
    //返回数据形式为json
    success: function (result) {

        //请求成功时执行该函数内容，result即为服务器返回的json对象
        if (result) {
            var json = eval(result);
            for (var i = 0; i < json.length; i++) {
                if (json[i].urban_rural == "城镇") {
                    if (json[i].type.search("收入") != -1) {
                        urbanIncomeType.push(json[i].type);
                        urbanIncomeValue.push(json[i].value);
                        urbanIncomeList.push({
                            //通过把result进行遍历循环来获取数据并放入Echarts中
                            name: json[i].type,
                            value: json[i].value
                        });
                    } else {
                        urbanExpenditureType.push(json[i].type);
                        urbanExpenditureValue.push(json[i].value);
                        urbanExpenditureSum = urbanExpenditureSum + json[i].value;
                    }
                }
                else {
                    if (json[i].type.search("收入") != -1) {
                        ruralIncomeType.push(json[i].type);
                        ruralIncomeValue.push(json[i].value)
                        ruralIncomeList.push({
                            //通过把result进行遍历循环来获取数据并放入Echarts中
                            name: json[i].type,
                            value: json[i].value
                        });
                    } else {
                        ruralExpenditureType.push(json[i].type);
                        ruralExpenditureValue.push(json[i].value);
                        ruralExpenditureSum = ruralExpenditureSum + json[i].value;
                    }
                }
            }
        }
    }
});

//排序
for (var i = 0; i < urbanExpenditureValue.length; i++) {
    for (var j = 0; j < urbanExpenditureValue.length - 1; j++) {
        if (urbanExpenditureValue[j] > urbanExpenditureValue[j + 1]) {
            var t = urbanExpenditureValue[j];
            urbanExpenditureValue[j] = urbanExpenditureValue[j + 1];
            urbanExpenditureValue[j + 1] = t;
            var k = urbanExpenditureType[j];
            urbanExpenditureType[j] = urbanExpenditureType[j + 1];
            urbanExpenditureType[j + 1] = k;
        }
    }
}

for (var i = 0; i < ruralExpenditureValue.length; i++) {
    for (var j = 0; j < ruralExpenditureValue.length - 1; j++) {
        if (ruralExpenditureValue[j] > ruralExpenditureValue[j + 1]) {
            var t = ruralExpenditureValue[j];
            ruralExpenditureValue[j] = ruralExpenditureValue[j + 1];
            ruralExpenditureValue[j + 1] = t;
            var k = ruralExpenditureType[j];
            ruralExpenditureType[j] = ruralExpenditureType[j + 1];
            ruralExpenditureType[j + 1] = k;
        }
    }
}